home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5408 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help with pointer alignment
  5. Date: Thu, 08 Feb 96 14:21:13 GMT
  6. Organization: none
  7. Message-ID: <823789273snz@genesis.demon.co.uk>
  8. References: <4fb0op$8l8@hermes.louisville.edu>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4fb0op$8l8@hermes.louisville.edu>
  15.            arwild01@homer.louisville.edu "Alan Wild" writes:
  16.  
  17. >I am having a small problem with pointer alignment in a library I am
  18. >developing. lint reports:
  19. >
  20. >"queue.c", line 13: warning: possible pointer alignment problem, op CAST
  21. >
  22. >And the code is as follows:
  23. >
  24. >struct  dataChain {
  25. >        ORD64           dataf;
  26. >        ORD64           be;
  27. >        int             cycle;
  28. >struct  dataChain       *next;
  29. >};
  30. >
  31. >typedef struct dataChain queueentry;
  32. >
  33. >void Append ( queueentry new, queue *Q ) {
  34. >
  35. >        queueentry *temp = (queueentry *)malloc( sizeof( queueentry ) );
  36.  
  37. Did you include stdlib.h? It is generally better not to cast the return
  38. value of malloc if you are using an ANSI compiler (which you probably are
  39. since you are used a function prototype). ANSI malloc should be declared in
  40. stdlib.h as returning void * and a reasonable compiler should not complain
  41. about converting void * to a pointer to object type. Non-ANSI header files
  42. might declare malloc as returning char *. In that case the cast is necessary
  43. and it is reasonable for a good compiler to warn about alignment problems.
  44. However in this case that warning can safely be ignored.
  45.  
  46. -- 
  47. -----------------------------------------
  48. Lawrence Kirby | fred@genesis.demon.co.uk
  49. Wilts, England | 70734.126@compuserve.com
  50. -----------------------------------------
  51.